class Node < ActiveRecord::Base
  # add a non-database attribute that will be manipulated as part of query processing
  attr_accessor :highlight

  before_update :getLatLongFromAddress

  has_many :facets
  has_and_belongs_to_many :groups

  # TODO: change Lat and Long database types to float
  def getLatLongFromAddress
    # Get Lat and Long from service to be used later for Google Maps
    server = XMLRPC::Client.new2('http://rpc.geocoder.us/service/xmlrpc')
    result = server.call2('geocode', self.address)
    if not result[1][0].nil?
      self.lat  = result[1][0]['lat']
      self.long = result[1][0]['long']
    end
  end
end
